package api

import (
	"github.com/astaxie/beego"
	"goblog/models/dao"
	"goblog/models"
)

type LinkController struct {
	beego.Controller
	linkDao *dao.LinkDao
}

func (c *LinkController) Get() {
	if c.linkDao == nil {
		c.linkDao = new(dao.LinkDao)
	}
	page, _ := c.GetInt("page", 1)
	size, _ := c.GetInt("size", 10)
	name := c.GetString("name")
	term := new(dao.LinkTerm)
	term.Page = page
	term.Size = size
	term.Name = name
	c.linkDao.Find(term)
	c.Data["json"] = models.JsonSuccess("", term);
	c.ServeJSON()
}

func (c *LinkController) Delete() {
	if c.linkDao == nil {
		c.linkDao = new(dao.LinkDao)
	}
	id, _ := c.GetInt(":id", 0)
	if id > 0 {
		c.linkDao.Del(id)
	}
	c.Data["json"] = models.JsonSuccess("", nil);
	c.ServeJSON()
}
